package com.sctvcloud.dongqu.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.jiongbull.jlog.JLog;
import com.ruihang.generalibrary.ui.adapter.BaseHolderAbsAdapter;
import com.ruihang.generalibrary.ui.util.OnItemInternalClick;
import com.sctvcloud.dongqu.R;
import com.sctvcloud.dongqu.beans.SearchKeyWords;
import com.sctvcloud.dongqu.ui.adapter.holder.SearchHistoryFootHolder;
import com.sctvcloud.dongqu.ui.adapter.holder.SearchHistoryHolder;

import java.util.List;

/**
 * Created by Administrator on 2017/6/28 0028.
 */

public class SearchHistoryAdapter extends BaseHolderAbsAdapter<SearchKeyWords, SearchHistoryHolder> {
    public SearchHistoryAdapter(Context context, List<SearchKeyWords> list) {
        super(context, list);
    }

    @Override
    public int getItemCount() {
        if (data != null) {
            int c = data.size();
            if (c > 0) {
                return c + 1;
            }
        }
        return 0;
    }

    @Override
    public SearchKeyWords getItem(int position) {
        if (position==getDataSize()){
            return new SearchKeyWords(true);

        }
        return super.getItem(position);
    }

    @Override
    public int getItemViewType(int position) {
        if (position==getDataSize()){
            return 1;
        }
        return super.getItemViewType(position);
    }

    @Override
    public SearchHistoryHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if (viewType==0) {
            View view = LayoutInflater.from(context).inflate(R.layout.item_search_history, parent, false);
            SearchHistoryHolder searchHistoryHolder = new SearchHistoryHolder(context, view);
            searchHistoryHolder.setInternalClick(this);
            return searchHistoryHolder;
        }else {
            View view = LayoutInflater.from(context).inflate(R.layout.item_search_history_foot, parent, false);
            SearchHistoryFootHolder searchHistoryHolder = new SearchHistoryFootHolder(context, view);
            searchHistoryHolder.setInternalClick(this);
            return searchHistoryHolder;
        }
    }
    @Override
    public SearchHistoryAdapter setItemInternalClick(OnItemInternalClick itemInternalClick) {
        super.setItemInternalClick(itemInternalClick);
        return this;
    }


}
